function ObjectDo() {

}

ObjectDo.deepClone = function (obj) {
    var result, oClass = ObjectDo.isClass(obj);
    //确定result的类型
    if (oClass === "Object") {
        result = {};
    } else if (oClass === "Array") {
        result = [];
    } else {
        return obj;
    }
    for (key in obj) {
        var copy = obj[key];
        if (ObjectDo.isClass(copy) == "Object") {
            result[key] = arguments.callee(copy);//递归调用
        } else if (ObjectDo.isClass(copy) == "Array") {
            result[key] = arguments.callee(copy);
        } else {
            result[key] = obj[key];
        }
    }
    return result;
}

ObjectDo.isClass = function (o) {
    if (o === null) return "Null";
    if (o === undefined) return "Undefined";
    return Object.prototype.toString.call(o).slice(8, -1);
}

ObjectDo.toString = function(obj, maxDepth = 4, before = "", depth = 0) {
    before = before || "";
    depth = depth || 0;
    maxDepth = maxDepth || 4;
    var str = "";
    if (typeof(obj) == "string") {
        str += "\"" + obj + "\"";
    }
    else if (typeof(obj) == "number") {
        str += obj;
    }
    else if (obj instanceof Array) {
        if (depth > maxDepth) {
            return "...";
        }
        str = "[\n";
        for (var i = 0; i < obj.length; i++) {
            str += before + " " + ObjectDo.toString(obj[i], maxDepth, before + " ", depth + 1) + (i < obj.length - 1 ? ",\n" : "\n");
        }
        str += before + "]";
    }
    else if (obj instanceof Object) {
        if (depth > maxDepth) {
            return "...";
        }
        str = "{\n";
        for (var key in obj) {
            str += before + " \"" + key + "\": " + ObjectDo.toString(obj[key], maxDepth, before + " ", depth + 1);
            str += ",\n";
        }
        if (str.slice(str.length - 2, str.length) == ",\n") {
            str = str.slice(0, str.length - 2) + "\n";
        }
        str += before + "}";
    }
    else {
        str += obj;
    }
    return str;
}

ObjectDo.keys = function(obj) {
    var list = [];
    for (var key in obj) {
        list.push(key);
    }
    return list;
}

global.lib.ObjectDo = ObjectDo;